<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
            name:"laowang",
            age:18
        }

        // 对象的原型下加方法 - Symbol.iterator
        Object.prototype[Symbol.iterator] = function(){
            // console.log(this);
            // 获取对象当中有几个属性-属性名
            const keys = Object.keys(this); //['name', 'age']
            // console.log(keys);

            const len = keys.length;

            // console.log(len);

            // 设置初始值
            let index = 0;

            return {
                next:function(){
                    return {
                        value:keys[index],
                        done: index++>=len
                    };
                }
            }
        }

        for(let item of obj){
            console.log(item);
        }


        // let arr = [1,2,3,4];

        // console.log(arr);

        // // Symbol(Symbol.iterator)
        // // console.log(arr.toString);

        // console.log(arr[Symbol.iterator]);

        // let newArr = arr[Symbol.iterator]();

        // console.log(newArr);

        // let val = newArr.next();

        // console.log(val); //{value: 1, done: false}

        // let val2 = newArr.next();

        // console.log(val2); //{value: 2, done: false}

        // let val3 = newArr.next();

        // console.log(val3); //{value: 3, done: false}

        // let val4 = newArr.next();

        // console.log(val4); //{value: 4, done: false}

        // let val5 = newArr.next();

        // console.log(val5); //{value: undefined, done: true}




    </script>
</body>
</html>